﻿//====================初始化验证表单====================
$(function () {
    //提交表单
    $("#btnSubmit").bind("click", function () {
        if ($("#txtUserName").val() == "" || $("#txtPassword").val() == "") {
            layer.alert('请填写用户名和登录密码！', {
                title: '提示框',
                icon: 0,
            });
            return false;
        }
        $.ajax({
            type: "POST",
            url: $("#loginform").attr("url"),
            dataType: "json",
            data: {
                "txtUserName": $("#txtUserName").val(),
                "txtPassword": $("#txtPassword").val(),
                "txtCode": $("#txtCode").val()
            },
            timeout: 20000,
            beforeSend: function (XMLHttpRequest) {
                $("#btnSubmit").attr("disabled", true);
                $("#msgtips").text("正在登录，请稍候...");
            },
            success: function (data, textStatus) {
                if (data.status == 1) {
                    location.href = data.url;
                } else {
                    $("#btnSubmit").attr("disabled", false);
                    $("#msgtips").text(data.info);
                    layer.alert(data.info, {
                        title: '提示框',
                        icon: 0,
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $("#msgtips").text("状态：" + textStatus + "；出错提示：" + errorThrown);
                $("#btnSubmit").attr("disabled", false);
            }
        });
        return false;
    });
});